<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <title>运维相关  &middot; sitename</title>
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="HandheldFriendly" content="True">
<meta name="MobileOptimized" content="320">
<meta name="viewport" content="width=device-width, initial-scale=1">


<meta name="description" content="运维相关 description" />

<meta name="keywords" content="one, two, ">


<meta property="og:title" content="运维相关  &middot; sitename ">
<meta property="og:site_name" content="sitename"/>
<meta property="og:url" content="https://lvzongcheng.gitee.io/redis/%E8%BF%90%E7%BB%B4%E7%9B%B8%E5%85%B3/" />
<meta property="og:locale" content="en-EN">


<meta property="og:type" content="article" />
<meta property="og:description" content="运维相关 description"/>
<meta property="og:article:published_time" content="2017-05-13T00:00:00Z" />
<meta property="og:article:modified_time" content="2017-05-13T00:00:00Z" />

  
    
<meta property="og:article:tag" content="one">
    
<meta property="og:article:tag" content="two">
    
  

  

<script type="application/ld+json">
  {
    "@context": "http://schema.org",
    "@type": "Article",
    "headline": "运维相关",
    "author": {
      "@type": "Person",
      "name": "LvZongCheng"
    },
    "datePublished": "2017-05-13",
    "description": "运维相关 description",
    "wordCount":  157 
  }
</script>



<link rel="canonical" href="https://lvzongcheng.gitee.io/redis/%E8%BF%90%E7%BB%B4%E7%9B%B8%E5%85%B3/" />

<link rel="apple-touch-icon-precomposed" sizes="144x144" href="https://lvzongcheng.gitee.io/touch-icon-144-precomposed.png">
<link href="https://lvzongcheng.gitee.io/favicon.png" rel="icon">

<meta name="generator" content="Hugo 0.60.0" />

  <!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->

<link href='https://fonts.googleapis.com/css?family=Merriweather:300%7CRaleway%7COpen+Sans' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="/css/font-awesome.min.css">
<link rel="stylesheet" href="/css/style.css">
<link rel="stylesheet" href="/css/highlight/default.css">

  
  
	<script>
	  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
	  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
	  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
	  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

	  ga('create', 'Your Google Analytics tracking code', 'auto');
	  ga('send', 'pageview');

	</script>

</head>
<body>
  <main id="main-wrapper" class="container main_wrapper has-sidebar">
    <header id="main-header" class="container main_header">
  <div class="container brand">
  <div class="container title h1-like">
  <a class="baselink" href="https://lvzongcheng.gitee.io">
  LvZongCheng

</a>

</div>

  
<div class="container topline">
  
  淡定 执著 进取 自律


</div>


</div>

  <nav class="container nav primary no-print">
  

<a class="homelink" href="https://lvzongcheng.gitee.io">home</a>


  
<a href="https://lvzongcheng.gitee.io/framework" title="Show list of Frameworks">Frameworks</a>

<a href="https://lvzongcheng.gitee.io/java" title="Show list of Java">Java</a>

<a href="https://lvzongcheng.gitee.io/linux" title="Show list of Linux">Linux</a>

<a href="https://lvzongcheng.gitee.io/redis" title="Show list of Redis">Redis</a>

<a href="https://lvzongcheng.gitee.io/sql" title="Show list of SQL">SQL</a>

<a href="https://lvzongcheng.gitee.io/Spring" title="Show list of Spring">Spring</a>

<a href="https://lvzongcheng.gitee.io/tools" title="Show list of Tools">Tools</a>

<a href="https://lvzongcheng.gitee.io/webpage" title="Show list of WebPage">WebPage</a>

<a href="https://lvzongcheng.gitee.io/information" title="Show list of information">information</a>

<a href="https://lvzongcheng.gitee.io/network" title="Show list of network">network</a>

<a href="https://lvzongcheng.gitee.io/%E5%BE%AE%E6%9C%8D%E5%8A%A1" title="Show list of 微服务">微服务</a>

<a href="https://lvzongcheng.gitee.io/%E6%80%BB%E7%BB%93" title="Show list of 总结">总结</a>

<a href="https://lvzongcheng.gitee.io/%E6%9C%BA%E5%99%A8%E8%87%AA%E5%8A%A8%E5%8C%96" title="Show list of 机器自动化">机器自动化</a>

<a href="https://lvzongcheng.gitee.io/%E6%B1%87%E7%BC%96" title="Show list of 汇编">汇编</a>

<a href="https://lvzongcheng.gitee.io/%E8%AE%B0%E4%BA%8B%E6%9C%AC" title="Show list of 记事本">记事本</a>


</nav>

<div class="container nav secondary no-print">
  
<a id="contact-link-email" class="contact_link" rel="me" aria-label="Email" href="mailto:Lyc19880405@163.com">
  <span class="fa fa-envelope-square"></span></a>



<a id="contact-link-github" class="contact_link" rel="me" aria-label="Github" href="https://github.com/enten/hugo-boilerplate">
  <span class="fa fa-github-square"></span></a>




 


















</div>


  

</header>


<article id="main-content" class="container main_content single">
  <header class="container hat">
  <h1>运维相关
</h1>

</header>

  <div class="container content">
  <p>redis持久化，两种方式
1、rdb快照方式
2、aof日志方式</p>
<p>&mdash;&mdash;&mdash;-rdb快照&mdash;&mdash;&mdash;&mdash;
save 900 1
save 300 10
save 60 10000</p>
<p>stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /var/rdb/</p>
<p>&mdash;&mdash;&mdash;&ndash;Aof的配置&mdash;&mdash;&mdash;&ndash;
appendonly no # 是否打开 aof日志功能</p>
<p>appendfsync always #每一个命令都立即同步到aof，安全速度慢
appendfsync everysec
appendfsync no 写入工作交给操作系统，由操作系统判断缓冲区大小，统一写入到aof  同步频率低，速度快</p>
<p>no-appendfsync-on-rewrite yes 正在导出rdb快照的时候不要写aof
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb</p>
<p>./bin/redis-benchmark -n 20000</p>
<p>&mdash;&mdash;&mdash;主从复制&mdash;&mdash;&mdash;&mdash;&mdash;-</p>
<p>Master配置
1：关闭rdb快照（备份工作交给slave）
2：可以开启aof</p>
<p>slave配置：
1、声明slave-of
2、某一个slave打开rdb快照功能
3、配置是否只读 slave-read-only
##4、可选配置密码（内网可不必）
##在主服务器配置中修改  requirepass 123456
##客户端连上后需要  auth 123456才能访问
##但是从服务器已经连不成功master,需要在从服务器配置上  masterauth 123456</p>
<p>cp redis.conf redis6380.conf
cp redis.conf redis6381.conf</p>
<p>pidfile /var/run/redis6380.pid
port 6380
dbfilename dump6380.rdb
dir /var/rdb/</p>
<p>注：每次slave断开后，再次连接master时，都要master全部dump出来rdb再aof，即同步的过程需要重新来一遍
所以要记住，多台slave最好不要一下都启动起来</p>
<p>&mdash;&mdash;&mdash;&mdash;-redis运维命令&mdash;&mdash;&mdash;&mdash;&ndash;
TIME 查看时间戳与微秒数
127.0.0.1:6379&gt; time</p>
<ol>
<li>&ldquo;1423329581&rdquo;</li>
<li>&ldquo;398972&rdquo;</li>
</ol>
<p>dbsize 查看当前库中的key数量
bgrewriteaof 后台进程重写aof
bgsave  后台保存rdb快照
save  保存rdb快照
lastsave  上次保存时间
slaveof  设为slave服务器
flushall  清空所有db
flushdb 清空当前db
shutdown save|nosave  断开连接关闭服务器</p>
<p>slowlog显示慢查询
(多慢才算慢？ slowlog-log-slower-than 10000)
存多少条？ slowlog-max-len 128 
查看慢日志  slowlog get
config get slowlog-log-slower-than 
config set slowlog-log-slower-than 10</p>
<p>info  显示服务器信息
config get 获取配置信息
config set 设置配置信息
monitor 打开控制台
sync  主从同步
client list 客户端列表
client kill 关闭某个客户端
client setname 为客户端设置名字
client getname 获取客户端名字</p>
<hr>
<p>&mdash;&mdash;-重要注意事项&mdash;&mdash;&mdash;-
如果不小心flushall了
应该首先关闭redis服务进程     shutdown nosave
然后编辑aof
重启</p>

</div>


  
</article>
      <footer id="main-footer" class="container main_footer">
  

  <div class="container nav foot no-print">
  
<a href="https://lvzongcheng.gitee.io/license">license</a>


  <a class="toplink" href="#">back to top</a>

</div>

  <div class="container credits">
  
<div class="container footline">
  
  code with <!-- raw HTML omitted --><!-- raw HTML omitted -->


</div>


  
<div class="container copyright">
  
  (c) 2015 yourname.


</div>


</div>

</footer>

    </main>
    
<script type="text/javascript">
  (function() {
    
    
    if (window.location.hostname == "localhost")
      return;
    var dsq = document.createElement('script'); dsq.async = true; dsq.type = 'text/javascript';
    dsq.src = '//your_disqus_shortname.disqus.com/count.js';
    (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
  })();
</script>



<script src="/js/highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script>



    
  </body>
</html>

